/*
 * @Author: DUST
 * @Date: 2023-05-26 15:11:50
 * @LastEditors: DUST
 * @LastEditTime: 2023-06-12 17:30:55
 * @FilePath: \koa-node-ts\app\middleware\accessLogMIddleware.ts
 * @Description:
 * undefined
 */
import { Context, Next } from "koa";
import { accessLogger } from "../logger";

async function accessLogMIddleware(ctx: Context, next: Next) {
  const req = ctx.req;
  const ip = req.headers['public-ip']
  // ctx.req.connection.socket.remoteAddress;
  console.log("公网IP：", ip);

  const str = `path:${ctx.path} | ip:${ip} | method:${ctx.method} | user-agent:${ctx.header["user-agent"]}`;
  accessLogger.info(str);
  return next();
}

export default accessLogMIddleware;
